<template>
    <div class="app-container record">
        <span class="title">阅读记录</span>
        <hr>
        <ul class="list">
            <li class="item" v-for="(item,index) in list" :key="index" @click="goToInfo(item)">
                <div class="item-name">
                    <span class="name-label">[{{item.type|typeSet}}]</span>
                    <span class="name" v-html="item.title">俄罗斯的阳光、绿茵、足球还不够？我们这里有大汉堡、小姐姐...</span>
                </div>
                <span class="item-time">{{item.createDate | dataYMD}}</span>
            </li>
        </ul>
        <div class="pagination">
            <el-pagination  @current-change="handleCurrentChange" :current-page.sync="currentPage" :page-size="pageSize" layout="total, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import {selectReadRecord} from '@/api/index'
import moment from "moment";
export default {
  data() {
    return {
      currentPage: Number(this.$route.query.currentPage)||1,
      list:[],
      pageSize:10,
      total:0
    };
  },
  components: {},
  created(){
    this.init(this.currentPage);
  },
  //时间过滤器
  filters: {
    dataHM: function(el) {
      return moment(el).format("h:mm");
    },
    dataYMD: function(el) {
      return moment(el).format("YYYY-MM-DD HH:mm");
    },
    typeSet: function(el) {
      if(el == 1){
        return "图书"
      }else if(el == 2){
        return "悦读"
      }
      else if(el == 3){
        return "视听"
      }
       else if(el == 7){
        return "视听"
      }
      else if(el == 4){
        return "报纸"
      }
      else if(el == 5){
        return "期刊"
      }
    }
  },
   watch: {
    '$route'(){
      console.log(this.currentPage)
      this.init(this.currentPage);
    }
  },
  methods: {
    goToInfo(item){
      switch (item.type) {
        case "1":
           this.$router.push("/book/info?bookId=" + item.fileId+"&bookName="+item.title );
          break;
       case "2":
          this.$router.push("/read/content?articleId="+item.fileId+"&title="+item.title+"&cover="+item.imgurl);  
          break;
       case "3":
           this.$router.push({path:"/videomusic/video_nocontent",query:{video:JSON.stringify(item)}
      });
          break;
       case "4":
          this.$router.push("/newspaper/info?max_file_name="+item.describ.slice(0,4)+"&resourceType=4&value="+item.fileId);
          break;
       case "5":
         this.$router.push("/periodical/info?max_file_name="+item.describ.slice(0,4)+"&resourceType=5&value="+item.fileId);
          break;  
       case "7":
         this.$router.push({
           path:"/record_videocontent",
           query:{
             "item":JSON.stringify(item)
           }
         });
          break;    
        default:
          break;
      }
    },
    init(pageNo){
      selectReadRecord(pageNo,this.pageSize).then(res=>{
        this.total = res.data.date.total
        this.list = res.data.date.list
      })
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.$router.push(this.$route.path + "?currentPage=" + this.currentPage);
    }
  }
};
</script>
<style lang="less" scoped>
.record {
  width: 100%;
  .title {
    font-size: 24px;
    margin-bottom: 20px;
    display: block;
  }
  hr {
    margin: 0px;
  }
  .list {
    padding: 0px;
    margin-bottom: 30px;
    .item {
      display: flex;
      justify-content: space-between;
      padding: 20px 0;
      border-bottom: 1px solid #eaeaea;
      cursor: pointer;
      span {
        display: inline-block;
      }
      .item-name {
        font-size: 18px;
        overflow: hidden;
        .name-label {
          float: left;
        }
        .name {
          float: left;
          width: 550px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
      .item-time {
        font-size: 16px;
        color: #a1a1a1;
      }
    }
  }
}
</style>


